package com.wheelpicker.base;

import android.support.annotation.NonNull;
import android.view.View;
import android.widget.TextView;

import com.jincp.common.dialog.BaseDialogFragment;
import com.wheelpicker.R;

/**
 * Created by jzxiang on 16/4/19.
 */
public abstract class BasePickerDialog<Config extends BasePickerConfig> extends BaseDialogFragment implements View.OnClickListener {
    protected Config mPickerConfig;


    protected abstract void initialize(Config pickerConfig);

    protected abstract void initCustomView(View view);

    protected abstract void onSureClicked();

    @Override
    protected void convertView(@NonNull View container, BaseDialogFragment dialogFragment) {
        View toolbar = container.findViewById(R.id.ll_title);
        TextView cancel = (TextView) container.findViewById(R.id.tv_cancel);
        cancel.setOnClickListener(new CloseClickListener());
        TextView sure = (TextView) container.findViewById(R.id.tv_sure);
        sure.setOnClickListener(this);
        TextView title = (TextView) container.findViewById(R.id.tv_title);

        toolbar.setBackgroundColor(mPickerConfig.mThemeColor);
        title.setText(mPickerConfig.mTitleString);
        title.setTextColor(mPickerConfig.mToolBarTVColor);
        cancel.setText(mPickerConfig.mCancelString);
        cancel.setTextColor(mPickerConfig.mToolBarTVColor);
        sure.setText(mPickerConfig.mSureString);
        sure.setTextColor(mPickerConfig.mToolBarTVColor);

        initCustomView(container);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.wheel_picker_layout;
    }

    @Override
    public void onClick(View v) {
        int id = v.getId();
        if (id == R.id.tv_sure){
            onSureClicked();
        }
    }
}
